<!--tvm票款差异协查-->
<template>
  <div class="conductorTicketChaYiShenhe Add el-card is-always-shadow el-card__body">
    <el-dialog
      title="编辑操作"
      :visible.sync="dialogVisible"
      @close="closed"
      width="950px">
      <avue-form v-if="isReload" class="conductorTicketChaYiShenheForm" ref='conductorTicketChaYiShenheForm' :option="option" v-model="formData" @submit="handleSubmit">

        <template slot-scope="scope" slot="lineCode">
          <el-select v-model="formData.lineCode" placeholder="请选择" style="width: 150px" @change="changeLine" clearable :disabled="showType==3 || showType==1" filterable>
            <el-option
              v-for="(item,index) in lineCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="stationCode">
          <el-select v-model="formData.stationCode" placeholder="请选择" style="width: 150px" clearable @change="changeStation" :disabled="showType==3 || showType==1" filterable>
            <el-option
              v-for="(item,index) in stationCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="conductorPersonName">
          <el-select v-model="formData.conductorPersonName" filterable placeholder="请选择" style="width: 150px" @change="(v)=>{formData.conductorPersonName=v.nikename;formData.conductorJobNo=v.userCode}" clearable :disabled="showType==3 || showType==1">
            <el-option
              v-for="(item,index) in conductorPersonNames"
              :key="index"
              :label="item.nikename"
              :value="item">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="conductorJobNo">
          <el-select v-model="formData.conductorJobNo" placeholder="请选择" style="width: 150px" clearable :disabled="true"  filterable>
            <el-option
              v-for="(item,index) in conductorPersonNames"
              :key="index"
              :label="item.userCode"
              :value="item.userCode">
            </el-option>
          </el-select>
        </template>

        <template slot-scope="scope" slot="equipmentNumber">
          <el-select v-model="formData.equipmentNumber" placeholder="请选择" style="width: 150px" clearable :disabled="showType==3 || showType==1" >
            <el-option
              v-for="(item,index) in operationCodes"
              :key="index"
              :label="item.operationCode"
              :value="item.operationCode">
            </el-option>
          </el-select>
        </template>

        <template slot-scope="scope" slot="sysAmount">
          <el-input-number v-model="formData.sysAmount" controls-position="right" :precision="2" @change="(v)=>{formData.differenceAmount=formData.paidAmount-v-formData.marketTicketAmount-formData.passengerWorkAmount-formData.singleTicketAmount-formData.emergencyAmount}"></el-input-number>
        </template>
        <template slot-scope="scope" slot="differenceAmount">
          <el-input-number v-model="formData.differenceAmount" controls-position="right" :precision="2" :disabled="showType==3 || showType==1"></el-input-number>
        </template>
        <template slot-scope="scope" slot="paidAmount">
          <el-input-number v-model="formData.paidAmount" controls-position="right" :precision="2" :disabled="true"></el-input-number>
        </template>
        <template slot-scope="scope" slot="marketTicketAmount">
          <el-input-number v-model="formData.marketTicketAmount" controls-position="right" :precision="2" :disabled="true"></el-input-number>
        </template>
        <template slot-scope="scope" slot="passengerWorkAmount">
          <el-input-number v-model="formData.passengerWorkAmount" controls-position="right" :precision="2" :disabled="true"></el-input-number>
        </template>
        <template slot-scope="scope" slot="singleTicketAmount">
          <el-input-number v-model="formData.singleTicketAmount" controls-position="right" :precision="2" :disabled="true"></el-input-number>
        </template>
	 <template slot-scope="scope" slot="emergencyAmount">
          <el-input-number v-model="formData.emergencyAmount" controls-position="right" :precision="2" :disabled="true"></el-input-number>
        </template>

        <template slot-scope="scope" slot="menuForm">
          <el-button type="primary" @click="closed">返回</el-button>
        </template>
      </avue-form>
    </el-dialog>
  </div>
</template>


<script>
  import {
    fenExYuangettoFixed,
    getgetStationCodes,
    getLineCodes,
    getSwPmDeviceOperationCodeList,
    qianxiangType
  } from "../../../../api/subwayRat/commonCheck";
  import {
    addSwAuCenterConductorAmountDifference,
    getAddOption, updateSwAuCenterConductorAmountDifference
  } from "../../../../api/subwayRat/conductorDifferences/conductorTicketChaYiShenhe/conductorTicketChaYiShenhe";
  import {getPersonRole} from "../../../../api/subwayRat/reportMondify/reportMistakeInfo";

  export default {
    components:{
    },
    data() {
      return {
        isReload:true,
        //1编辑，2添加，3预览
        showType:1,
        dialogVisible:true,
        lineCodes:[],
        selectedKeys:[],
        stationCodes:[],
        conductorPersonNames:[],//售票员名称
        operationCodes:[],
        formData:{
          lineCode:'',
          stationCode:'',
          dynamic: []
        },
        option:{
        }
    }
    },
    created() {
    },
    methods: {
      handleSubmit(form,done){
        let param={};
        Object.assign(param,this.formData);
        this.formatterAmount(param,false);
        if(this.showType==2){
          addSwAuCenterConductorAmountDifference(param).then(res=>{
            if(res.data.code==0){
              this.$message.success("操作成功！");
              this.closed();
              this.$parent.getList();
            }else{
              this.$message.error("操作失败！");
            }
          }).catch((e)=>{
            this.$message.error("操作失败！");
          });
        }else if(this.showType==1){
          updateSwAuCenterConductorAmountDifference(param).then(res=>{
            if(res.data.code==0){
              this.$message.success("操作成功！");
              this.closed();
              this.$parent.getList();
            }else{
              this.$message.error("操作失败！");
            }
          }).catch((e)=>{
            this.$message.error("操作失败！");
          });
        }
        done();
      },
      recallShow(id,row,showType){
        this.showType=showType;
        this.getOption();
        if(showType==1){ //编辑时
          this.formData=JSON.parse(JSON.stringify(row));
          this.formatterAmount(this.formData,true);
          this.loadStation(row.lineCode);
          this.changeStation(row.stationCode);

        }else if(showType==2){//添加
          this.$refs.conductorTicketChaYiShenheForm.clearVal();
        }
      },
      closed(){
        this.dialogVisible=false;
        this.$parent.isShowDia=false;
      },
      getOption(){
        let th=this;
        this.option=getAddOption(th);
        this.isReload=false;
        this.$nextTick(()=>{
          this.isReload=true;
        })
      },
      async getSheBei(){
        let res=[];
        await getSwPmDeviceOperationCodeList({lineCode:this.formData.lineCode,stationCode:this.formData.stationCode}).then(r=>{
          res=r.data.data;
        });
        this.operationCodes=res;
        return res;
      },
      formatterAmount(row,isYuan){ //格式化钱
        if(isYuan){
            row.sysAmount=fenExYuangettoFixed(row,'sysAmount');
            row.differenceAmount=fenExYuangettoFixed(row,'differenceAmount');
            row.paidAmount=fenExYuangettoFixed(row,'paidAmount');
            row.marketTicketAmount=fenExYuangettoFixed(row,'marketTicketAmount');
            row.passengerWorkAmount=fenExYuangettoFixed(row,'passengerWorkAmount');
            row.singleTicketAmount=fenExYuangettoFixed(row,'singleTicketAmount');
	    row.emergencyAmount=fenExYuangettoFixed(row,'emergencyAmount');
        }else if(!isYuan){
            row.sysAmount=Number(row.sysAmount)*100;
            row.differenceAmount=Number(row.differenceAmount)*100;
            row.paidAmount=Number(row.paidAmount)*100;
            row.marketTicketAmount=Number(row.marketTicketAmount)*100;
            row.passengerWorkAmount=Number(row.passengerWorkAmount)*100;
            row.singleTicketAmount=Number(row.singleTicketAmount)*100;
	    row.emergencyAmount=Number(row.emergencyAmount)*100;
        }
        return row;
      },
      changeLine(v){ //改变线路时
        getgetStationCodes(v).then(res=>{
          this.stationCodes=res;
          this.formData.stationCode='';
        });
      },
      loadStation(v){ //加载线路的站点
        getgetStationCodes(v).then(res=>{
          this.stationCodes=res;
        });
      },
      changeStation(v){
        getPersonRole({roleCode:'ZHANWURENYUAN',lineCode:this.formData.lineCode,stationCode:v}).then((res)=>{
          this.conductorPersonNames=res.data.data;
        });
        this.getSheBei();
      }
    },
    mounted() {
      getLineCodes().then(res=>{ //获取线路
        this.lineCodes=res;
      });
    }
  }
</script>
<style lang="scss">
  .huLianWangShouPiaojiDataInput.EditorOrAdd{
    .avue-group[index='2']{
      .avue-form__group{
        .avue-form__row{
          width: 100%;
        }
      }
    }
    @media only screen and (min-width: 992px){
      width: 100%;
    }
    .avue-crud__tip{
      display: none;
    }
  }

</style>
